$(function(){
    var push_Center = $('#pushCenter');
    var today = $('#doc').data('today');
    var messageListModal = $('#messageListModal');
    var message_list = $('.message_list');
    var close_message = $('.close_message');
    var nothing_pushListBody = $('#nothing_pushListBody');
    var pushListBody = $('#pushListBody');
    var nothing_warnListBody = $('#nothing_warnListBody');
    var warnListBody = $('#warnListBody');
    var nothing_checkListBody = $('#nothing_checkListBody');
    var checkListBody = $('#checkListBody');
    var soundToggleTrigger = $('#soundToggleTrigger');
    var adminId = $('#adminId').data("id");
    var title_text = $('title').text();
    var isIE = (navigator.userAgent.indexOf('MSIE')>=0) || (navigator.userAgent.indexOf('Trident')>=0);
    window.pushstyle = 'order';
    //切换推送列表
    var getTabChange = function(){
        if(window.pushstyle){
            switch(window.pushstyle){
                case 'order':
                    var messageTab = messageListModal.find('.order-tab');
                    var messageContent = message_list.find('.order-content');
                    break;
                case 'warn':
                    var messageTab = messageListModal.find('.warn-tab');
                    var messageContent = message_list.find('.warn-content');
                    break;
                case 'check':
                    var messageTab = messageListModal.find('.check-tab');
                    var messageContent = message_list.find('.check-content');
                    break;                         
            }  
            messageTab.addClass('message-active').siblings('.message-tab').removeClass('message-active');
            messageContent.removeClass('hidden').siblings('.message-content').addClass('hidden');            
        }
    };
    $('#messageListModal').on('click','.message-tab',function(e){
        e.stopPropagation();
        var btn = $(this);
        if(btn.hasClass('order-tab')){
            window.pushstyle = 'order';
        }else if(btn.hasClass('warn-tab')){ 
            window.pushstyle = 'warn';
        }else{
            window.pushstyle = 'check';
        }
        getTabChange();
    });     
    
    //运动效果
    var movement = push_Center.find('.push_right');
    var getMoving = function(property){
        if(property){
            movement.css({'width':"140px"});
        }else{
            movement.css({'width':"0px"});
        }
    };
    
    push_Center.on('mouseenter',function(e){
        e.stopPropagation(); 
        getMoving(true);           
    }).on('mouseleave',function(e){
        e.stopPropagation();     
        getMoving(false);
    }).on('click','.push-content .push_right ',function(e){
        e.stopPropagation();
        $('#messageListModal').modal('show');
        getTabChange();
    });
    close_message.on('click',function(e){
        e.stopPropagation();
        $('#messageListModal').modal('hide');
        getMoving(false);
    });
    
    //推送订单初始化
    var requestOrderHtml = function(){
        var pushMessageHTML = '';
        ajaxRequest('/Home/NewsPush/getNewsList',{},'post', function(data) {
            hideMainLoading();
            nothing_pushListBody.addClass('hidden');
            pushListBody.addClass('hidden');
            var info = data.data;
            if(info.length!==0){
                $.each(info, function(key, value) {
                    var templatePushMessage = $($('#templatePushMessage').clone().html());
                    if(value.hour>0){
                       templatePushMessage.find('.list-hour').removeClass('hidden');
                       templatePushMessage.find('.list-hour .hotel_name').text(value.hotelName);
                       templatePushMessage.find('.list-hour .room_name').text(value.roomName);
                       templatePushMessage.find('.list-hour .enter_time').text(value.startTime);
                       templatePushMessage.find('.list-hour .push_hour').text(value.hour);
                       if(value.type == 1){
                           templatePushMessage.find('.list-hour .room-out-label').removeClass('hidden');
                       }else{
                           templatePushMessage.find('.list-hour .room-enter-label').removeClass('hidden');
                       }
                   }else{
                       templatePushMessage.find('.list-night').removeClass('hidden');
                       templatePushMessage.find('.list-night .hotel_name').text(value.hotelName);
                       templatePushMessage.find('.list-night .room_name').text(value.roomName);
                       templatePushMessage.find('.list-night .enter_time').text(value.startTime);
                       templatePushMessage.find('.list-night .push_night').text(value.nights);
                       if(value.type == 1){
                           templatePushMessage.find('.list-night .room-out-label').removeClass('hidden');
                       }else{
                           templatePushMessage.find('.list-night .room-enter-label').removeClass('hidden');
                       }
                   }
                   templatePushMessage.attr('data-parent',value.orderInfoId);
                   templatePushMessage.attr('data-value',value.orderRoomId);
                   templatePushMessage.attr('data-room',value.roomId);
                   templatePushMessage.attr('data-hotel',value.hotel);
                   templatePushMessage.find('.list_right').attr({'data-relateid':value.newsPushRelateId,'data-pushid':value.newsPushId,'data-hotel':value.hotel});
                   pushMessageHTML += templatePushMessage.prop('outerHTML');
                }); 
                pushListBody.html(pushMessageHTML);  
                pushListBody.removeClass('hidden');              
            }else{
                pushListBody.addClass('hidden');
                nothing_pushListBody.removeClass('hidden');
            }
        }, function(error) {
            hideMainLoading();
            if(error.responseJSON.status == 700){
                pushListBody.addClass('hidden');
                nothing_pushListBody.removeClass('hidden');
            }
        });            
    }   
    
    //推送消息初始化
    var requestWarnHtml = function(){
        ajaxRequest('/Home/Hotel/getRemindList', {
            "currentPage": 1,
            "pageSize": 30,
            "remind": 1,
            "isRead": 0
        }, 'post', function(data) {
            hideMainLoading();
            nothing_warnListBody.addClass('hidden');
            warnListBody.removeClass('hidden');
            var info = data.data;
            var WarnListHTML = '';
            if(info.remindList){
                if(info.remindList.length !== 0){
                    $.each(info.remindList, function(key, value) {
                        var templateWarnHTML = $($('#templatePushWarn').clone().html());
                        templateWarnHTML.find('.hotel_name').text(value.hotelName);
                        templateWarnHTML.find('.warn_time').text(value.remindDate);
                        templateWarnHTML.find('.Warn_content').text(value.content);
                        templateWarnHTML.attr('data-alarmClockId',value.alarmClockId);
                        templateWarnHTML.attr('data-hotel',value.hotel);
                        WarnListHTML += templateWarnHTML.prop('outerHTML');
                    });
                }            
            }else{
                warnListBody.addClass('hidden');
                nothing_warnListBody.removeClass('hidden');            
            }
            warnListBody.html(WarnListHTML);
        }, function(error) {
            
        });  
    }    
    
    //推送查房初始化
    var requestCheckHtml = function(){
        ajaxRequest('/Home/NewsPush/getRoomCheck', {
            "hotel": window.currentHotel,
        }, 'post', function(data) {
            hideMainLoading();
            nothing_checkListBody.addClass('hidden');
            checkListBody.removeClass('hidden');
            var info = data.data;
            var checkListHTML = '';
            if(info.roomCheck.length !== 0){
                $.each(info.roomCheck, function(key, value) {
                    var templateCheckHTML = $($('#templatePushCheck').clone().html());
                    templateCheckHTML.find('.hotel_name').text(value.hotelName);
                    templateCheckHTML.find('.check_room').text(value.roomName);
                    templateCheckHTML.find('.check_remark').text(value.remark);
                    templateCheckHTML.find('.check_content').text(value.checkCost);
                    templateCheckHTML.attr('data-checkid',value.id);
                    checkListHTML += templateCheckHTML.prop('outerHTML');
                });
            }else{
                checkListBody.addClass('hidden');
                nothing_checkListBody.removeClass('hidden');            
            }   
            checkListBody.html(checkListHTML);
        }, function(error) {
            
        });  
    }       
    
    //获取声音
    var warnAudioIE = $('#warnAudioIE').get(0);
    var chatAudioIE = $('#chatAudioIE').get(0);
    var checkAudioIE = $('#checkAudioIE').get(0);
    var warnAudio = $('#warnAudio').get(0);
    var chatAudio = $('#chatAudio').get(0);
    var checkAudio = $('#checkAudio').get(0);
    
    var getChatAudio = function(){
        isIE ? chatAudioIE.play() : chatAudio.play();
    }
    var getWarnAudio = function(){
        isIE ? warnAudioIE.play() : warnAudio.play();      
    }
    var getCheckAudio = function(){
        isIE ? checkAudioIE.play() : checkAudio.play();       
    }    
    //推送数量
    var getHotelNewsCount = function(pushstyle,type){
        ajaxRequest('/Home/NewsPush/getHotelNewsCount', {
            "hotel": window.currentHotel,
            "adminId":adminId
        }, 'post', function(data) {
            var voiceStatus = data.data.voiceStatus;
            var newsCount = parseInt(data.data.newsCount);
            var newsNum = parseInt(data.data.remindCountNews);   
            var checkNum = parseInt(data.data.checkCount);     
            //声音提示
            if(type !== 3){
                if (parseInt(voiceStatus) == 0) {       
                    if(pushstyle == 'order'){
                        if(newsCount>0){
                            fuFlashing(newsCount,title_text);
                            getChatAudio();
                        }
                    }   
                    if(pushstyle == 'warn'){
                        if(newsNum>0){
                            getWarnAudio();
                        }
                    }
                    if(pushstyle == 'check'){
                        if(checkNum>0){
                            getCheckAudio();
                        }
                    }      
                };                  
            };
            if(newsNum>0){
                messageListModal.find('.warninfos').addClass('active');
            } 
            if(newsCount>0){
                messageListModal.find('.infos').addClass('active');
            } 
            if(checkNum>0){
                messageListModal.find('.checkinfos').addClass('active');
            }    
            if(newsNum>0 || newsCount> 0 || checkNum>0){
                getMoving(true);
            }
            push_Center.find('.messages').data('count',newsCount).data('num',newsNum).data('check',checkNum).text('('+(newsCount+newsNum+checkNum)+')');
            messageListModal.find('.infos').text('('+newsCount+')');
            messageListModal.find('.warninfos').text('('+newsNum+')'); 
            messageListModal.find('.checkinfos').text('('+checkNum+')'); 
        }, function(error) { 
            
        });
    }
 
    //订单通信
    var socket = null;
    if (typeof WebSocket == 'function') {
        socket = new WebSocket(window.pushServer);
    } else if (typeof MozWebSocket == 'function') {
        socket = new MozWebSocket(window.pushServer);
    }
    if (socket !== undefined && socket !== null) {
        socket.onopen = function () {
            socket.send(JSON.stringify({
                hotel: window.currentHotel,
                "adminId":adminId
            }));
        };
        socket.onmessage = function (e) {
            var data = $.parseJSON(e.data);
            window.pushstyle = 'order';
            getHotelNewsCount('order',data.type);
            requestOrderHtml();
        };
        socket.onclose = function () {};
    };    
    
    //提醒通信
    var warnSocket = null;
    if (typeof WebSocket == 'function') {
        warnSocket = new WebSocket(window.remindServer);
    } else if (typeof MozWebSocket == 'function') {
        warnSocket = new MozWebSocket(window.remindServer);
    }
    if (warnSocket !== undefined && warnSocket !== null) {
        warnSocket.onopen = function () {
            warnSocket.send(JSON.stringify({
                hotel: window.currentHotel,
                "adminId": adminId
            }));
        };
        warnSocket.onmessage = function (e) {
            var data = $.parseJSON(e.data);
            window.pushstyle = 'warn';
            getHotelNewsCount('warn');
            requestWarnHtml();
        };
        warnSocket.onclose = function () {};
    };       
   
    //查房通信
    var checkSocket = null;
    if (typeof WebSocket == 'function') {
        checkSocket = new WebSocket(window.checkServer);
    } else if (typeof MozWebSocket == 'function') {
        checkSocket = new MozWebSocket(window.checkServer);
    }
    if (checkSocket !== undefined && checkSocket !== null) {
        checkSocket.onopen = function () {
            checkSocket.send(JSON.stringify({
                hotel: window.currentHotel,
                "adminId":adminId
            }));
        };
        checkSocket.onmessage = function (e) {
            var data = $.parseJSON(e.data);
            window.pushstyle = 'check';
            getHotelNewsCount('check');
            requestCheckHtml();
        };
        checkSocket.onclose = function () {};
    };
    
    var getCountshow = function(state){
        var newsCount = parseInt(push_Center.find('.messages').data('count'));
        var newsNum = parseInt(push_Center.find('.messages').data('num'));
        var checkNum = parseInt(push_Center.find('.messages').data('check'));
        switch(state){
            case 0:
                newsCount = 0;
                pushListBody.addClass('hidden');
                nothing_pushListBody.removeClass('hidden');
                messageListModal.find('.infos').removeClass('active');
                break;            
            case 1:
                newsCount--;
                if(newsCount<=0){
                    newsCount = 0;
                    pushListBody.addClass('hidden');
                    nothing_pushListBody.removeClass('hidden');
                    messageListModal.find('.infos').removeClass('active');
                }
                break;
            case 2:
                newsNum--;
                if(newsNum<=0){
                    newsNum = 0;
                    warnListBody.addClass('hidden');
                    nothing_warnListBody.removeClass('hidden');
                    messageListModal.find('.warninfos').removeClass('active');
                }
                break;
            case 3:
                checkNum--;
                if(checkNum<=0){
                    checkNum = 0;
                    checkListBody.addClass('hidden');
                    nothing_checkListBody.removeClass('hidden');
                    messageListModal.find('.checkinfos').removeClass('active');
                }
                break;                         
        } 
        messageListModal.find('.infos').text('('+newsCount+')');
        messageListModal.find('.warninfos').text('('+newsNum+')');
        messageListModal.find('.checkinfos').text('('+checkNum+')');
        push_Center.find('.messages').data('count',newsCount).data('num',newsNum).data('check',checkNum).text('('+(newsCount+newsNum+checkNum)+')');
    }

    //删除推送消息
    pushListBody.on('click','.list_right',function(e){
        e.preventDefault()
        e.stopPropagation(); 
        var submitBtn = $(this);
        var remove = submitBtn.closest('.li_list');
        var newsPushRelateId = submitBtn.data('relateid');
        var newsPushId = submitBtn.data('pushid');
        ajaxRequest('/Home/NewsPush/saveNews', {
            "hotel": window.currentHotel,
            "newsPushRelateId":newsPushRelateId,
            "newsPushId":newsPushId,
            "type": 1,
        }, 'post', function(data) {
            remove.remove();
            getCountshow(1);
        }, function(error) { 
        });  
    });
    message_list.on('click','.all_remove',function(e){
        e.preventDefault()
        e.stopPropagation(); 
        var submitBtn = $(this);
        var newsNum = parseInt(push_Center.find('.messages').data('num'));
        var checkNum = parseInt(push_Center.find('.messages').data('check'));
        ajaxRequest('/Home/NewsPush/saveNews', {
            "hotel": window.currentHotel,
            "newsPushRelateId":0,
            "newsPushId":0,
            "type": 3,
        }, 'post', function(data) {
            getCountshow(0);
        }, function(error) { 
        }); 
    })
    
    
    //删除推送提醒消息
    warnListBody.on('click','.list_right',function(e){
        e.preventDefault()
        e.stopPropagation(); 
        var submitBtn = $(this);
        var newsCount = parseInt(push_Center.find('.messages').data('count'));
        var newsNum = parseInt(push_Center.find('.messages').data('num'));
        var checkNum = parseInt(push_Center.find('.messages').data('check'));
        var remove = submitBtn.closest('.li_list');
        var alarmClockId = remove.data('alarmclockid');
        var currentHotel = remove.data('hotel');
        ajaxRequest('/Home/Hotel/saveRemind', {
            "hotel": currentHotel,
            "alarmClockId":alarmClockId,
            "isRead":1
        }, 'post', function(data) {
            remove.remove();
            getCountshow(2);
        }, function(error) { 
        });  
    });    

    //删除推送查房消息
    checkListBody.on('click','.list_right',function(e){
        e.preventDefault()
        e.stopPropagation(); 
        var submitBtn = $(this);
        var newsCount = parseInt(push_Center.find('.messages').data('count'));
        var newsNum = parseInt(push_Center.find('.messages').data('num'));
        var checkNum = parseInt(push_Center.find('.messages').data('check'));
        var remove = submitBtn.closest('.li_list');
        var checkId = remove.data('checkid');
        ajaxRequest('/Home/NewsPush/setRoomCheckType', {
            "hotel": window.currentHotel,
            "checkId":checkId
        }, 'post', function(data) {
            remove.remove();
            getCountshow(3);
        }, function(error) { 
        });  
    });   


    //声音设置
    var voicestatus = $('#soundToggleTrigger').data('type');
    if(parseInt(voicestatus) == 0){  
        $('#soundSwitch').addClass('is-checked').attr('data-type',1);
        soundToggleTrigger.find('.sound_toggle').text(lang('open'));
    }else{
        $('#soundSwitch').removeClass('is-checked').attr('data-type',0);
        soundToggleTrigger.find('.sound_toggle').text(lang('close'));
    }
    $('#soundSwitch').on('click',function(){
        var thisBtn = $(this);
        var type = parseInt(thisBtn.attr('data-type'));
        ajaxRequest('/Home/NewsPush/setVoice', {
            "hotel": window.currentHotel,
            'type' : type
        }, 'post', function(data) {
            var info = data.data;    
            if(type == 1){
                thisBtn.attr('data-type',0);
                thisBtn.removeClass('is-checked');
                soundToggleTrigger.find('.sound_toggle').text(lang('close'));
            }else{
                thisBtn.attr('data-type',1);
                thisBtn.addClass('is-checked');
                soundToggleTrigger.find('.sound_toggle').text(lang('open'));
            }
        }, function(error) { 
            
        });
    });

    //备忘录
    $('#requestBlack').on('click',function(){
        var content = $('#textareaBlack').val();
        $('.form-group').removeClass('has-warning');
        $('.form-group').removeClass('has-error');
        ajaxRequest('/Home/Hotel/saveBlackboard', {
            "hotel": window.currentHotel,
            'blackBoardContent' : content
        }, 'post', function(data) {
            formInlineTip($('#requestBlack'), lang('successfullySave'), 2);
            $('#remindToggleModal').modal('hide');
            if(data.data.blackBoardContent !== ''){
                $('#blackBoard .board-little-red').removeClass('hidden');
            }else{
                $('#blackBoard .board-little-red').addClass('hidden');
            }
            
        }, function(error) {
            formInlineTip($('#requestBlack'), error.responseJSON.info);
        });
    });
    $('#blackBoard').on('click',function(){
        $('.form-group').removeClass('has-warning');
        $('.form-group').removeClass('has-error');
    });
    ajaxRequest('/Home/Hotel/getBlackboard', {
        "hotel": window.currentHotel
    }, 'post', function(data) {
        if(data.data.blackBoardContent !== ''){
            $('#textareaBlack').val(data.data.blackBoardContent);
            $('#blackBoard .board-little-red').removeClass('hidden');
        }else{
            $('#blackBoard .board-little-red').addClass('hidden');
        }
    }, function(error) {
        formInlineTip($('#requestBlack'), error.responseJSON.info);
    });
    //定时提醒列表
    var getWarnlist = function(){
        ajaxRequest('/Home/Hotel/getRemindList', {
            "hotel": window.currentHotel,
            "currentPage": 1,
            "pageSize": 30,
            "remind": 0,
            "isRead": 0
        }, 'post', function(data) {
            var info = data.data; 
            var WarnListHTML = '';
            if(info.remindList){
                if(info.remindList.length>0){
                    $.each(info.remindList, function(key, value) {
                        var templateWarnHTML = $($('#templateWarnList').clone().html());
                        templateWarnHTML.find('.editor-warn').attr('data-alarmClockId',value.alarmClockId);
                        templateWarnHTML.find('.remove-warn').attr('data-alarmClockId',value.alarmClockId);
                        templateWarnHTML.find('.time').text(value.remindDate);
                        templateWarnHTML.find('.content').text(value.content);
                        templateWarnHTML.find('.lastoperate').text(value.recentOperator);
                        WarnListHTML += templateWarnHTML.prop('outerHTML');
                    });
                }               
            }else{
                WarnListHTML = $('#templateWarnEmpty').clone().html();
            } 
            $('#warnList').html(WarnListHTML);
        }, function(error) {
            
        });        
    };
    $('#warnReception').on('click',function(){
        getWarnlist();
    });
    //添加提醒
    var addWarnToggleModal = $('#addWarnToggleModal');
    var requestAddWarn = $('#requestAddWarn');
    $('#warnToggleModal').on('click','.add-warn',function(){
        requestAddWarn.removeAttr('data-alarmClockid');
        $('#warnTime').val(getNowDate(1));
        $('#warnContent').val('');
        addWarnToggleModal.modal('show');
    });
    $('#warnTime').fdatepicker({
        format: 'yyyy-mm-dd hh:ii',
        pickTime:true,
        startDate: today,
        endDate: '2038-01-01',
    });  
    addWarnToggleModal.on('click','.close',function(){
        $('.datepicker').attr('style','display: none; top: 241px; left: 426.5px; z-index: 1060;');
    });
    requestAddWarn.on('click',function(){
        var btn = $(this);
        var alarmClockId = btn.attr('data-alarmClockid');
        $('.form-group').removeClass('has-warning');
        $('.form-group').removeClass('has-error');
        var warnTime = $('#warnTime').val();
        if(Date.parse(new Date(warnTime))/1000 < Date.parse(new Date(getNowDate()))/1000){
            formInlineTip(btn, lang('warnWorng'));
            return false;
        }
        var warnContent = $('#warnContent').val();
        if(warnContent == ''){
            formInlineTip(btn, lang('warnNull'));
            return false;
        }
        var param = {};
        param.hotel = window.currentHotel;
        param.remindDate = warnTime;
        param.content = warnContent;
        if(alarmClockId){
            param.alarmClockId = alarmClockId;
        }
        ajaxRequest('/Home/Hotel/saveRemind',param, 'post', function(data) {
            formInlineTip(btn, lang('successfullySave'),2);
            addWarnToggleModal.modal('hide');
            getWarnlist();
        }, function(error) {
            formInlineTip(btn, error.responseJSON.info);
        });
    });
    
    //修改信息
    $('#warnList').on('click','.editor-warn',function(){
        var alarmClockId = $(this).data('alarmclockid');
        var param = {};
        param.hotel = window.currentHotel;
        param.alarmClockId = alarmClockId;        
        ajaxRequest('/Home/Hotel/getRemind',param, 'post', function(data) {
            var info = data.data;
            $('#warnTime').val(info.remindDate);
            $('#warnContent').val(info.content);
            requestAddWarn.attr('data-alarmClockid',info.alarmClockId);
            addWarnToggleModal.modal('show');
        }, function(error) {
        });        
    });
    //删除信息
    $('#warnList').on('click','.remove-warn',function(){
        var alarmClockId = $(this).data('alarmclockid');
        var listItem = $(this).closest('.list-item');
        var param = {};
        param.hotel = window.currentHotel;
        param.alarmClockId = alarmClockId;   
        param.dropRemind = 1;      
        ajaxRequest('/Home/Hotel/saveRemind',param, 'post', function(data) {
           layer.msg(lang('successfullyDel'),{time:1000}); 
           listItem.remove();
        }, function(error) {
        });        
    });       
    
    //记一笔
    push_Center.on('click','.project-content .push_right ',function(e){
        e.stopPropagation();
        var submitBtn = $(this);
        $('#booksTime').val(today);
        $('#booksPrice').val('');
        $('#booksModal').modal('show');
    });    
    $('#booksTime').fdatepicker({
        format: 'yyyy-mm-dd',
        startDate: "2000-01-01",
        endDate: '2060-01-01',
    }); 
    $('.booksProjectTypeMenu').on('click','li',function(){
        var submitbtn = $(this); 
        submitbtn.addClass('active').siblings('li').removeClass('active');
        submitbtn.closest('.dropdown').find('.booksProjectType').attr('data-value',submitbtn.data('value')).find('.info').text(submitbtn.find('a').text());
    });  
    $('.booksReceiveTypeMenu').on('click','li',function(){
        var submitbtn = $(this); 
        submitbtn.addClass('active').siblings('li').removeClass('active');
        $('#booksReceiveType').attr('data-value',submitbtn.data('value')).find('.info').text(submitbtn.find('a').text());
    });    
    var incomeProject = $('.income-project');
    var expendProject = $('.expend-project');
    $('.content-panel-project').on('click','.project-list',function(){
        $me = $(this);
        var value = $me.data('value');
        $me.addClass('active').siblings().removeClass('active');
        $('#confirmBooksInfo').data('value',value);
        if(value == 1){
            expendProject.addClass('hidden');
            incomeProject.removeClass('hidden');
        }else{
            incomeProject.addClass('hidden');
            expendProject.removeClass('hidden');
        }
        $('#booksPrice').val('');
    });        
    $('#booksPrice').focus(function(){
        $('#booksModal .form-group').removeClass('has-error');
    });
    $('#confirmBooksInfo').on('click',function(){
        var submitBtn = $(this);
        var type = $('#confirmBooksInfo').data('value');
        var price = $('#booksPrice').val().trim();
        var project= $('#booksReceiveType').data('value');
        if(price == ''){
            formInlineTip(submitBtn, lang('constant.sumNull'));
            return false;
        }
        if(type == 1){
            var noteId = $('.income-project .booksProjectType').data('value');
        }else{
            var noteId = $('.expend-project .booksProjectType').data('value');
        }
        if(noteId == ''){
            formInlineTip(submitBtn, lang('constant.project'));
            return false;
        }
        var param = {
                hotel: window.currentHotel,
                noteId: noteId,
                payId:project,
                type: type,
                price:price,
                noteDate:$('#booksTime').val(),
                remark:$('#booksRemark').val()
        };
        ajaxRequest('/Home/Hotel/addNoteCost', param, 'post',function(data){
            $('#booksModal').modal('hide');
            layer.msg(lang('successfullySave'),{time:1000}); 
        } , function(error) {
            if (error.responseJSON === undefined) {
                formInlineTip(submitBtn, lang('tip.server'));
            } else {
                formInlineTip(submitBtn, error.responseJSON.info);
            }
        }, submitBtn);        
        
    })
    var reqTimestamp = (new Date()).valueOf();
    $.getScript("/Public/dist/Home/BookPage/roomclean.js?" + reqTimestamp);
    $.getScript("/Public/jslib/lodop/lodop.min.js?" + reqTimestamp);
    
    //多元货币
    ajaxRequest('/Home/Hotel/saveHotelDefaultCurrency', {
        "hotel": window.currentHotel,
    }, 'POST', function (data) {
        if(!data.data.isSetDefaultCurrency){
            $('#multiCurrencyModal').modal('show');
        };
    }, function (error) {
        
    });    
    
    $('#multiCurrencyModal').on('click', '.dropdown-menu li>a', function(e) {
        var item = $(this);
        var liItem = item.parents('li');
        var toggle = liItem.parents('.dropdown-menu').siblings('[data-toggle="dropdown"]');
        liItem.addClass('active');
        liItem.siblings().removeClass('active');
        var value = liItem.data('value');
        var name = item.text();
        toggle.data('value', value);
        toggle.find('.info').html(name);       
    });    
    $('#confirmCurrencyInfo').on('click',function(e){
        var currencyId = $('#multiCurrencyModal').find('[data-toggle="dropdown"]').data('value');
        var name = $('#multiCurrencyModal .info').text();
        $('#confirmCurrencyModal .name').text(name);
        $('#confirmCurrencyModal').show();
        $('#confirmCurrencyBtn').attr('data-value',currencyId);
    });
    $('#confirmCurrencyModal').on('click','.close',function(e){
        e.stopPropagation();
        $('#confirmCurrencyModal').hide();
    });
    $('#confirmCurrencyBtn').on('click',function(e){
        e.stopPropagation();
        var submitBtn = $(this);
        var currencyId = submitBtn.attr('data-value');
        ajaxRequest('/Home/Hotel/saveHotelDefaultCurrency', {
            "hotel": window.currentHotel,
            "currencyId":currencyId
        }, 'POST', function (data) {
            $('#confirmCurrencyModal').hide();
            $('#multiCurrencyModal').modal('hide');
            formInlineTip(submitBtn, lang('successfullySet'),2);
            window.location.reload();
        }, function (error) {
            if (error.responseJSON === undefined) {
                formInlineTip(submitBtn, lang('tip.server'));
            } else {
                formInlineTip(submitBtn, error.responseJSON.info);
            }
        });            
    });    
    
    //引导页
    var guidancePageStatisticsOriginal = $('#guidancePageStatisticsOriginal');
    var guidancePageGuestOriginal = $('#guidancePageGuestOriginal');
    var guidancePageOrderOriginal = $('#guidancePageOrderOriginal');
    var guidancePageBookOriginal = $('#guidancePageBookOriginal');
    var guidanceContainer = $('#guidance-container');
    ajaxRequest('/Home/GuidancePage/getGuidanceData', {
        'guidances':'first',
    }, 'post', function(data){
        if(data.data.first){
            guidanceContainer.removeClass('hidden');
        };
    },null);
    $('.first-guidance').on('click','.next-step',function(e){
        $('.first-guidance').addClass('hidden');
        $('.second-guidance-box').removeClass('hidden');
    });
    $('.second-guidance-box').on('click','.next-step',function(e){
        $('.second-guidance-box').addClass('hidden');
        $('.thirdly-guidance-box').removeClass('hidden');
    });
    $('.thirdly-guidance-box').on('click','.next-step',function(e){
        $('.thirdly-guidance-box').addClass('hidden');
        $('.four-guidance-box').removeClass('hidden');
        if(guidancePageStatisticsOriginal.length == 0){
            $('#guidancePageStatistics').removeClass('hidden');
        }
    });
    $('.four-guidance-box').on('click','.next-step',function(e){
        $('.four-guidance-box').addClass('hidden');
        $('.five-guidance-box').removeClass('hidden');
        if(guidancePageStatisticsOriginal.length == 0){
            $('#guidancePageStatistics').addClass('hidden');
        }
        if(guidancePageOrderOriginal.length == 0){
            $('#guidancePageOrder').removeClass('hidden');
        }
    });
    $('.five-guidance-box').on('click','.next-step',function(e){
        $('.five-guidance-box').addClass('hidden');
        $('.six-guidance-box').removeClass('hidden');
        if(guidancePageOrderOriginal.length == 0){
            $('#guidancePageOrder').addClass('hidden');
        }
        if(guidancePageGuestOriginal.length == 0){
            $('#guidancePageGuest').removeClass('hidden');
        }
    });    
    $('.six-guidance-box').on('click','.next-step',function(e){
        $('.six-guidance-box').addClass('hidden');
        $('.seven-guidance-box').removeClass('hidden');
        $('.seven-guidance').removeClass('hidden');
        if(guidancePageGuestOriginal.length == 0){
            $('#guidancePageGuest').addClass('hidden');
        }
        if(guidancePageBookOriginal.length == 0){
            $('#guidancePageBook').removeClass('hidden');
        }
    });      
    $('.seven-guidance-box').on('click','.next-step',function(e){
        $('.seven-guidance-box').addClass('hidden');
        $('.eight-guidance-box').removeClass('hidden');
        $('.eight-guidance').removeClass('hidden');
        if(guidancePageBookOriginal.length == 0){
            $('#guidancePageBook').addClass('hidden');
        }
    }); 
    $('.eight-guidance').on('click','.next-step',function(e){
        ajaxRequest('/Home/GuidancePage/setGuidanceData', {
            'guidances':'first',
        }, 'post', function(data){
            guidanceContainer.addClass('hidden');
            $('.eight-guidance-box').addClass('hidden');
        });          
    });     
    $('.close-guidance').on('click',function(e){
        ajaxRequest('/Home/GuidancePage/setGuidanceData', {
            'guidances':'first',
        }, 'post', function(data){
            guidanceContainer.addClass('hidden');
            $('.second-guidance-box').addClass('hidden');
            $('.thirdly-guidance-box').addClass('hidden');
            $('.four-guidance-box').addClass('hidden');
            $('.five-guidance-box').addClass('hidden');
            $('.six-guidance-box').addClass('hidden');
            $('.seven-guidance-box').addClass('hidden');
            $('.eight-guidance-box').addClass('hidden');
            if(guidancePageStatisticsOriginal.length == 0){
                $('#guidancePageStatistics').addClass('hidden');
            }
            if(guidancePageGuestOriginal.length == 0){
                $('#guidancePageGuest').removeClass('hidden');
            }
            if(guidancePageOrderOriginal.length == 0){
                $('#guidancePageOrder').addClass('hidden');
            }
            if(guidancePageBookOriginal.length == 0){
                $('#guidancePageBook').addClass('hidden');
            }
        });          
    });           
});
//头部闪烁
var fuFlashing = function(news,title){
    var FlashingTime = 16;
    var timer = setInterval(function(){
        var iseven = parseInt(FlashingTime) % 2;
        if(FlashingTime <= 0){
            clearInterval(timer);
            $('title').text(title);
        }else{
            if(iseven === 0){
                $('title').text(lang('new')+news);
            }else{
                $('title').text(title);
            }
        }
        FlashingTime--;
    }, 500);
}
var showMainLoading = function() {
    $('#mainLoading').removeClass('hidden');
};
var hideMainLoading = function() {
    $('#mainLoading').addClass('hidden');
};
//获取当前时间
var getNowDate = function(type){
    var myDate = new Date();
    var year=myDate.getFullYear();
    var month=myDate.getMonth()+1;
    var date=myDate.getDate(); 
    var h=myDate.getHours(); 
    var m=myDate.getMinutes();
    var s=myDate.getSeconds();  
    var now=year+'-'+p(month)+"-"+p(date)+" "+p(h)+':'+p(m);    
    var show=year+'-'+p(month)+"-"+p(date)+" "+p(h)+':'+p(m); 
    if(type == 1){
        return show;
    }else{
        return now;
    }
}
function p(s) {
    return s < 10 ? '0' + s: s;
}